package cn.edu.neusoft.wuguangsheng.flowerimpression.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import cn.edu.neusoft.wuguangsheng.flowerimpression.Utils.TimeUtils;
import cn.edu.neusoft.wuguangsheng.flowerimpression.activity.FKnowInfoActivity;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.AllCollectionKnowBean;

public class UserFKnowAllCollectionAdapter extends BaseAdapter<AllCollectionKnowBean> {
    private String times;

    public UserFKnowAllCollectionAdapter(Context context, List<AllCollectionKnowBean> items, int layoutResourse) {
        super(context, items, layoutResourse);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView= LayoutInflater.from(context).inflate(layoutResourse,parent,false);
        UserFKnowAllCollectionViewHolder viewHolder = new UserFKnowAllCollectionViewHolder(itemView);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final UserFKnowAllCollectionViewHolder viewHolder=(UserFKnowAllCollectionViewHolder) holder;

        final AllCollectionKnowBean allCollectionKnowBean=items.get(position);

        final String title = allCollectionKnowBean.getFknow_title();
        final String time = allCollectionKnowBean.getFkc_cupdatetime();
        final String fknowid = allCollectionKnowBean.getFknow_id();
        final String typename = allCollectionKnowBean.getFknow_typename();

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date date = simpleDateFormat.parse(time);
            times = TimeUtils.getTimeFormatText(date);
        }catch (Exception e){
            e.printStackTrace();
        }

        viewHolder.allcollection_title.setText(title);
        viewHolder.allcollection_time.setText(times);
        viewHolder.allcollection_typename.setText(typename);

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, FKnowInfoActivity.class);
                intent.putExtra("fknow_id",fknowid);
                context.startActivity(intent);
            }
        });

    }
}
